from ConfigParser import SafeConfigParser

SETTINGS = {}

def load_settings():
    parser = SafeConfigParser()
    parser.readfp(open('settings.cfg'))
    sections = parser.sections()
    for section in sections:
        item_values = {}
        items = parser.items(section)
        for item in items:
            item_values[item[0]] = item[1]
        SETTINGS[section] = item_values
        
def save_settings():
    parser = SafeConfigParser()
    sections = SETTINGS.keys()
    for section in sections:
        options = SETTINGS[section].keys()
        for option in options:
            value = SETTINGS[section][option]
            parser.set(section, option, value)
    parser.write(open('settings', 'w'))
        
load_settings()